package com.zhang.learn.javaassist.utill;

import cn.afterturn.easypoi.entity.vo.BigExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;

import java.util.HashMap;

/**
 * @author zhanghaolian
 * @date 2021/7/22 0:34
 */
@Component
public class ExcelUtil {
    @Autowired
    private ExportLoadDataHandler dataHandler;

    /**
     * excel导出方法
     * @param param
     */
    public void export(ExcelParam param) {
        ModelMap map = new ModelMap();
        ExportParams params = new ExportParams(param.getTitle(), param.getSheetName(), ExcelType.XSSF);
        map.put(BigExcelConstants.CLASS, param.getDtoClass());
        map.put(BigExcelConstants.PARAMS, params);
        map.put(BigExcelConstants.FILE_NAME,param.getFileName());
        map.put(BigExcelConstants.DATA_PARAMS, new HashMap<String,String>());
        dataHandler.setData(param.getData());
        map.put(BigExcelConstants.DATA_INTER,dataHandler);
        PoiBaseView.render(map, param.getRequest(), param.getResponse(), BigExcelConstants.EASYPOI_BIG_EXCEL_VIEW);
    }
}
